package com.itbaizhan.shopping_manager_api.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itbaizhan.shopping_common.pojo.Goods;
import com.itbaizhan.shopping_common.result.BaseResult;
import com.itbaizhan.shopping_common.service.GoodsService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/goods")
public class GoodsController {
    @DubboReference
    private GoodsService goodService;

    @PostMapping("/add")
    public BaseResult add(@RequestBody Goods goods) {
        goodService.add(goods);
        return BaseResult.ok();
    }


    @PutMapping("/update")
    public BaseResult update(@RequestBody Goods goods) {
        goodService.update(goods);
        return BaseResult.ok();
    }

    @PutMapping("/putAway")
    public BaseResult putAway(@RequestParam("id") Long id, @RequestParam("isMarketable") Boolean isMarketable) {
        goodService.putAway(id, isMarketable);
        return BaseResult.ok();
    }

    @GetMapping("/findById")
    public BaseResult findById(@RequestParam("id") Long id) {
        Goods byId = goodService.findById(id);
        return BaseResult.ok(byId);
    }

    @GetMapping("/search")
    public  BaseResult<Page<Goods>> search(Goods goods,int page, int size){
        Page<Goods> search = goodService.search(goods, page, size);
        return BaseResult.ok(search);
    }
}